import React, { Component } from "react";
// 引入prop-types，用于props的类型检查
import PropTypes from "prop-types";

class Child extends Component {
  static propTypes = {
    name: PropTypes.string.isRequired,
    // age: PropTypes.number,
    age: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
  };
  render() {
    return (
      <div>
        child组件 - {this.props.name} - {this.props.age}
      </div>
    );
  }
}
// https://www.npmjs.com/package/prop-types
// Child.propTypes = {
//   name: PropTypes.string.isRequired,
//   // age: PropTypes.number,
//   age: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
// };

class App extends Component {
  render() {
    return (
      <>
        <h2>props的类型检查</h2>
        <Child name="pengshao" age="39" />
      </>
    );
  }
}

export default App;
